package com.alks.function.controller.finance.borad;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.common.data.thread.UserIdThread;
import com.alks.entity.data.entity.board.FinanceOtherCharges;
import com.alks.entity.data.entity.board.SysDictData;
import com.alks.entity.data.entity.dispatch.Vendor;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.mapper.board.BoardMapper;
import com.alks.function.service.boardService.BoardService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:hxl
 * @create: 2024-09-28 15:57
 * @Description:
 */
@Api(tags = "其他明细")
@ApiRestController("/other")
public class FinanceOtherController {
    @Autowired
    private BoardService boardService;

    @PostMapping("/loadInSumList")
    @ApiOperation(value = "查询")
    @WebLogger
    public ResponseInfo loadInSumList(@RequestBody FinanceOtherCharges financeOtherCharges) {
        return boardService.loadInSumList(financeOtherCharges);
    }

    @PostMapping({"/delete"})
    @ApiOperation(value = "删除")
    @WebLogger
    public ResponseInfo deleteDetail(@RequestBody List<FinanceOtherCharges> financeOtherCharges) {
        return boardService.deleteOtherDetail(financeOtherCharges);
    }

    @PostMapping({"/add"})
    @ApiOperation(value = "新增")
    @WebLogger
    public ResponseInfo addOtherCharges(@RequestBody List<FinanceOtherCharges> financeOtherCharges) {
        return boardService.addOtherCharges(financeOtherCharges);
    }

    @PostMapping({"/updateDutyAmount"})
    @ApiOperation(value = "修改")
    @WebLogger
    public ResponseInfo updateDutyAmount(@RequestBody FinanceOtherCharges financeOtherCharges) {
        return boardService.updateDutyAmount(financeOtherCharges);
    }

    @PostMapping({"/updateOtherCfmFlag"})
    @ApiOperation(value = "检核")
    @WebLogger
    public ResponseInfo updateOtherCfmFlag(@RequestBody FinanceOtherCharges financeOtherCharges) {
        return boardService.updateOtherCfmFlag(financeOtherCharges);
    }

    @PostMapping({"/update/aoaMonth"})
    @ApiOperation(value = "修改aoaMonth")
    @WebLogger
    public ResponseInfo updateAoaMonth(@RequestBody List<FinanceOtherCharges> records, @RequestParam Date aoaMonth) {
        return boardService.updateAoaMonth(records, aoaMonth);
    }

    //其他费用导入\
    @PostMapping("/import")
    @ApiOperation(value = "导入")
    @WebLogger
    public ResponseInfo importOtherCharges(MultipartFile file) {
        return boardService.importOtherCharges(file);
    }

    @PostMapping("/downloadOtherCharges")
    @ApiOperation(value = "导出")
    @WebLogger
    public void downloadOtherCharges(@RequestBody FinanceOtherCharges financeOtherCharges, HttpServletResponse response) throws IOException {
        boardService.downloadOtherCharges(response, financeOtherCharges);
    }

    @Autowired
    BoardMapper boardMapper;

    @PostMapping("/list/combo")
    @ApiOperation(value = "供应商下拉框")
    @WebLogger
    public ResponseInfo listCombo(@RequestParam(required = false) String searchKey, @RequestParam Integer pageSize, @RequestParam Integer pageNum) {
        if (pageNum == null || pageSize == null){
            pageNum = 1;
            pageSize = 10;
        }
        Map<String,Object> map =  new HashMap<>();
        PageHelper.startPage(pageNum, pageSize);
        List<Vendor> list = boardMapper.searchAll(UserIdThread.get().getCompanyId(), searchKey);
        map.put("data",list);
        map.put("total",new PageInfo<Vendor>(list).getTotal());
        return ResponseInfo.ok(map);
    }

    @PostMapping({"/dicType/list"})
    @ApiOperation(value = "费用类型")
    @WebLogger
    public ResponseInfo listDicType(@RequestParam(required = false) String searchKey, @RequestParam Integer pageSize, @RequestParam Integer pageNum) {
        if (pageNum == null || pageSize == null){
            pageNum = 1;
            pageSize = 10;
        }
        PageHelper.startPage(pageNum, pageSize);
        Map<String,Object> map =  new HashMap<>();
        SysDictData dictData = new SysDictData();
        dictData.setDictType("other_charges_type");
        dictData.setDictLabel(searchKey);
        dictData.setStatus("0");
        List<SysDictData> data = boardMapper.selectDictDataList(dictData);
        map.put("data",data);
        map.put("total",new PageInfo<SysDictData>(data).getTotal());
        return ResponseInfo.ok(map);
    }

}
